<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/21 0021
 * Time: 10:47
 */

namespace api\modules\wechat\controllers;


use api\modules\BaseModulesController;
use common\components\Services\Wechat;

class ServicesController extends BaseModulesController
{
    public function actionIndex()
    {
        $this->authToken();
    }

    /**
     * 微信回调
     * @return string
     */
    public function actionCreate()
    {
        $wechat = new Wechat();
        $wechat->app->server->push(function($message) use ($wechat) {
            switch ($message['MsgType']) {
                case 'event':
                    return $wechat->eventHandler($message);
                    break;
                case 'text':
                    //return '收到文字消息';
                    //break;
                case 'image ':
                    //return '收到图片消息';
                    //break;
                case 'voice':
                    //return '收到语音消息';
                    //break;
                case 'video':
                    //return '收到视频消息';
                    //break;
                case 'location':
                    //return '收到坐标消息';
                    //break;
                case 'link':
                    //return '收到链接消息';
                    //break;
                case 'file':
                    //return '收到文件消息';
                    return 'OK';
                // ... 其它消息
                default:
                    return "SUCCESS";
                    break;
            }
        });
        echo $wechat->app->server->serve();
    }

    private function authToken()
    {
        #file_put_contents("D:\\temp.txt", $this->get("echostr"));
        echo $this->get("echostr");
        die;
    }
}